﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using SynapseGaming.LightingSystem.Core;
using SynapseGaming.LightingSystem.Components;
using SynapseGaming.LightingSystem.Lights;
using SynapseGaming.LightingSystem.Rendering;
using SynapseGaming.LightingSystem.Serialization;

namespace Game2
{
    /// <summary>
    /// Components that automatically serialize when the parent object (and scene)
    /// are saved, derive from the BaseComponentAutoSerialization class.
    /// 
    /// The type provided as the generic argument "<ISceneEntity>" determines what
    /// type of objects the component can be assigned to.
    /// 
    /// Components assigned to entities and scene objects must use the ISceneEntity
    /// type, components assigned to lights must use the ILight type.
    /// </summary>
    public class Control : BaseComponentAutoSerialization<ISceneEntity>
    {
        public override void OnUpdate(GameTime gametime)
        {
           KeyboardState keyboard = Keyboard.GetState();

            // Cast the Object the component is attached to, to a scene object 
            SceneObject sceneobject = (SceneObject)ParentObject;

            float modelRotation = 1.0f;

            // Rotate to the Left 
            if (keyboard.IsKeyDown(Keys.J))
            {
                float angle = (float)gametime.ElapsedGameTime.TotalSeconds * modelRotation;
                Matrix rotation = Matrix.CreateRotationY(angle);
                sceneobject.World = rotation * sceneobject.World;
            }
            // Rotate to the Right 
            if (keyboard.IsKeyDown(Keys.L))
            {
                float angle = (float)gametime.ElapsedGameTime.TotalSeconds * -modelRotation;
                Matrix rotation = Matrix.CreateRotationY(angle);
                sceneobject.World = rotation * sceneobject.World;
            }
        }

    }
}
